1 : <?php
2 : class iCalendarEvent {
3 :
4 : private $start;
5 : private $end;
6 : private $summary;
7 : private $description;
8 : private $mailto;
9 : private $facultative;
10 : private $wholeDay;
11 :
12 : // $start, $end, $summery, $description=null, $organizer=null
13 :
14 : public function __construct( $data ) {
15 7 : $this->wholeDay = $this->isWholeDay( $data );
16 7 : $this->start = $this->formatDate($data['start']);
17 7 : $this->end = (isset($data['end'])) ? $this->formatDate($data['end']) : null;
18 7 : $this->facultative = $this->isFacultative($data);
19 7 : $this->summary = $data['summary'];
20 7 : $this->description = $this->description($data);
21 7 : $this->mailto = (isset($data['mailto'])) ? $data['mailto'] : null;
22 7 : }
23 :
24 : public function formattedString() {
25 7 : $str = "BEGIN:VEVENT\n";
26 7 : $str .= ($this->mailto) ? "MAILTO:$this->mailto\n" : "";
27 7 : $str .= "SUMMARY:$this->summary";
28 7 : $str .= $this->facultative ? " (F)\n" : "\n";
29 7 : $str .= "DESCRIPTION:" . substr($this->description,0,100)."\n";
30 7 : $str .= "DTSTART:$this->start\n";
31 7 : $str .= ($this->end) ? "DTEND:$this->end\n" : "";
32 7 : $str .= "END:VEVENT\n";
33 :
34 7 : return $str;
35 : }
36 :
37 : private function description( $data ) {
38 7 : return $this->isFacultative( $data ) ? "(Fakultativer Termin) " . $data['description'] : $data['description'];
39 : }
40 :
41 : private function isFacultative( $data ) {
42 7 : return (isset($data['facultative']) && $data['facultative'] == true) ? true : false;
43 : }
44 :
45 : private function isWholeDay( $data ) {
46 7 : return (isset($data['wholeday']) && $data['wholeday'] == true);
47 : }
48 :
49 : private function formatDate( $date ) {
50 7 : $str = date("Ymd",strtotime($date));
51 :
52 7 : if ($this->wholeDay == true) return $str;
53 :
54 : $str .= "T"
55 6 : . date("His",strtotime($date));
56 :
57 6 : return $str;
58 : }
|